{js href="__ADMIN_PLUGINS__/gee-test/gt4.js" /}

<div class="row">
    <div class="col-xs-12" style="width: 100%;">
        <div class="form-group text-center">
            <div id="captcha" style="width: 260px;margin: 0 auto;"></div>
        </div>
    </div>
</div>

<script>

    initGeetest4({
        captchaId: '{$gt_captcha_id}',
        product: 'popup',
    }, function (gt) {
        window.gt = gt;
        gt.appendTo("#captcha").onSuccess(function () {
            let result = gt.getValidate();
            $.ajax({
                url: '{:url("auth/gt")}',
                data: result,
                dataType: 'json',
                success: function (res) {
                    console.log(res);
                }
            })
        })

        $("#loginButton").click(function (e) {
            let validate = gt.getValidate();
            if (!validate) {
                e.preventDefault();
                layer.msg('请先完成验证', {icon: 2});
                e.preventDefault();
                gt.showBox();
            } else {

            }
        });

    });

    function refreshCaptcha() {
        try {
            gt.reset();
        } catch (e) {

        }
    }
</script>